package com.example.ex02login;


import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ListviewActivity extends Activity implements OnClickListener{
   
	private Button btupdate,btclose  ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_listview);
	    TextView login = (TextView) findViewById(R.id.textlogin);
		EditText editlogin = (EditText)findViewById(R.id.editupdate);
		btupdate =(Button)findViewById(R.id.btupdate);
		btclose =(Button)findViewById(R.id.btclose);
		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
		String l =pref.getString("edit_login","login not set");
		String e =l;
	    login.setText(" Welcome   : " + l);
	    editlogin.setText(e);
	    btupdate.setOnClickListener(this);
        
   }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.listview, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.btupdate:
			Intent intents = new Intent(this,UpdateActivity.class);
			setResult(RESULT_OK, intents);
			EditText edit_login = (EditText) findViewById(R.id.editupdate);
			SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
			Editor editor = pref.edit();
			editor.putString("edit_login",edit_login.getText().toString() );
			editor.commit();
			startActivity(intents);
			finish();
			break;
		case R.id.btclose:	
			
		}
		

	}

}
